package com.xujiakai.car.maintain.domain.entity;

import com.xujiakai.car.maintain.infrastructure.mapper.DaoFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class Warehouse {
    private Integer id;

    private String warehousename;

    private String warehouseadd;

    private String remarks;

    private String wareflag;

    @Resource
    private DaoFactory daoFactory;


    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getWarehousename() {
        return warehousename;
    }

    public void setWarehousename(String warehousename) {
        this.warehousename = warehousename == null ? null : warehousename.trim();
    }

    public String getWarehouseadd() {
        return warehouseadd;
    }

    public void setWarehouseadd(String warehouseadd) {
        this.warehouseadd = warehouseadd == null ? null : warehouseadd.trim();
    }

    public String getRemarks() {
        return remarks;
    }

    public void setRemarks(String remarks) {
        this.remarks = remarks == null ? null : remarks.trim();
    }

    public String getWareflag() {
        return wareflag;
    }

    public void setWareflag(String wareflag) {
        this.wareflag = wareflag == null ? null : wareflag.trim();
    }

    public boolean modifyWarehouse(com.xujiakai.car.maintain.domain.dto.WarehouseDTO warehouse, String type) {
        boolean flag = false;
        if (warehouse != null && org.apache.commons.lang.StringUtils.isNotBlank(type)) {
            if ("C".equals(type)) {// 添加
                warehouse.setWareflag("1");
                flag = daoFactory.getWarehouseMapper().insertSelective(warehouse) > 0;
            } else if ("U".equals(type)) {// 修改
                flag = daoFactory.getWarehouseMapper().updateByPrimaryKeySelective(warehouse) > 0;
            } else if ("D".equals(type)) {// 删除
                com.xujiakai.car.maintain.domain.dto.WarehouseDTO wh = daoFactory.getWarehouseMapper().selectByPrimaryKey(warehouse.getId());
                if (wh != null) {
                    wh.setWareflag(warehouse.getWareflag());
                    flag = daoFactory.getWarehouseMapper().updateByPrimaryKeySelective(wh) > 0;
                }
            }
        }
        return flag;
    }
}